package Poly2;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:lenovo
 * Date:2024-06-04
 * Time:21:17
 */
public class Poly2Test {
    public static void main(String[] args) {
        /*Worker Jack=new Worker("Jack",5000);
        Manager Tim=new Manager("Tim",15000.0,5000);*/
        Employee Jack=new Worker("Jack",5000);
        Employee Tim=new Manager("Tim",15000.0,5000);
        //左边是编译类型，右边是运行类型

        Poly2Test poly2Test = new Poly2Test();

        poly2Test.getEmpAnnual(Jack);
        poly2Test.getEmpAnnual(Tim);

        poly2Test.testwork(Jack);
        poly2Test.testwork(Tim);

        System.out.println(Tim.toString());
        System.out.println(Tim);
        //默认调用了toString方法，等价于monster.toString();
    }

    public void getEmpAnnual(Employee e){
        System.out.println(e.getName()+":"+e.getSalary());
    }

    public void testwork(Employee e){
        //instanceof检查运行类型是否符合
        if(e instanceof Worker){
            ((Worker) e).work();
        }else if(e instanceof Manager){
            ((Manager) e).manage();
        }else {
            System.out.println("不做处理!");
        }
    }
}
